package cn.weiron.fun.sample.service.impl;


import cn.hutool.core.util.StrUtil;
import cn.weiron.fun.infrastructure.auth.Authority;
import cn.weiron.fun.infrastructure.dto.PageResult;
import cn.weiron.fun.sample.dto.RecordCountDto;
import cn.weiron.fun.sample.dto.RecordPageDto;
import cn.weiron.fun.sample.dto.SignRequestDto;
import cn.weiron.fun.sample.entity.ChangeLog;
import cn.weiron.fun.sample.entity.SamplePointSign;
import cn.weiron.fun.sample.mapper.SamplePointSignMapper;
import cn.weiron.fun.sample.result.RecordCount;
import cn.weiron.fun.sample.result.SamplePointSignRecord;
import cn.weiron.fun.sample.service.*;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.math.BigDecimal;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;

/**
 * (SamplePointSign)表服务实现类
 *
 * @author makejava
 * @since 2022-07-16 10:36:20
 */
@Service("samplePointSignServiceImpl")
@Slf4j
public class SamplePointSignServiceImpl extends ServiceImpl<SamplePointSignMapper, SamplePointSign> implements SamplePointSignService {
    @Autowired
    private SamplePointSignMapper samplePointSignDao;


    private final SamplePointTimeService samplePointTimeService;

    public SamplePointSignServiceImpl(@Qualifier("samplePointServiceImpl") SamplePointService samplePointService
                                      ,@Qualifier("samplePointTimeServiceImpl") @Lazy SamplePointTimeService samplePointTimeService
                                      ,@Qualifier("sampleTimeRecordServiceImpl") SampleTimeRecordService recordService) {
        this.samplePointService = samplePointService;
        this.samplePointTimeService = samplePointTimeService;
        this.recordService = recordService;
    }

    private final SamplePointService samplePointService;




    private final SampleTimeRecordService recordService;


    @Resource
    private Authority.AccountHandler  handler;

    @Resource
    private ChangeLogService changeLogService;

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public SamplePointSign queryById(Integer id) {
        return this.samplePointSignDao.queryById(id);
    }

    @Override
    public PageResult<SamplePointSign> queryByPage(SignRequestDto dto) {
        return null;
    }


    /**
     * 新增数据
     *
     * @param samplePointSign 实例对象
     * @return 实例对象
     */
    @Override
    public SamplePointSign insert(SamplePointSign samplePointSign) {
        this.samplePointSignDao.insert(samplePointSign);
        return samplePointSign;
    }

    /**
     * 修改数据
     *
     * @param samplePointSign 实例对象
     * @return 实例对象
     */
    @Override
    public SamplePointSign update(SamplePointSign samplePointSign) {
        this.samplePointSignDao.update(samplePointSign);
        return this.queryById(samplePointSign.getId());
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer id) {
        return this.samplePointSignDao.deleteById(id) > 0;
    }

    @Override
    public PageResult<SamplePointSignRecord> queryByYearAndMonth(RecordPageDto dto) {
        return null;
    }

    @Override
    public RecordCount queryCount(RecordCountDto dto) {
        return null;
    }


    @Override
    public void logRemark(HttpServletRequest request) {
        Authority.Account account = handler.get(request);
        ChangeLog log = account.getBean(ChangeLog.class);
        log.setCreateTime(LocalDateTime.now());
        changeLogService.save(log);
    }
}
